{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<Response [200]>\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[{'faceId': 'f273d867-2ed5-4f48-a790-c55661a30455',\n",
       "  'faceRectangle': {'top': 72, 'left': 84, 'width': 80, 'height': 80},\n",
       "  'faceAttributes': {'gender': 'male', 'age': 19.0, 'glasses': 'NoGlasses'}},\n",
       " {'faceId': '2a0bcb5e-27a7-45a5-aade-2b56415d99ea',\n",
       "  'faceRectangle': {'top': 66, 'left': 416, 'width': 75, 'height': 75},\n",
       "  'faceAttributes': {'gender': 'male', 'age': 21.0, 'glasses': 'NoGlasses'}},\n",
       " {'faceId': 'a9b10d93-6334-48f0-b7c1-06315d5b1a2b',\n",
       "  'faceRectangle': {'top': 74, 'left': 234, 'width': 70, 'height': 70},\n",
       "  'faceAttributes': {'gender': 'male', 'age': 18.0, 'glasses': 'NoGlasses'}}]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#调用requests\n",
    "import requests\n",
    "#调用json\n",
    "import json\n",
    "#AZURE人脸识别的地址\n",
    "BASE_URL =  'https://hzxnewmedia-face-identify.cognitiveservices.azure.com//face/v1.0/detect'\n",
    "#AZURE API的密钥\n",
    "KEY = 'c8e461586bbd4286b4f213c0e7529666'  \n",
    "#请求的头部信息\n",
    "HEADERS = {\n",
    "    'Content-Type': 'application/json',                          \n",
    "    'Ocp-Apim-Subscription-Key': '{}'.format(KEY),  \n",
    "}\n",
    "#所需检测的人脸图像链接\n",
    "img_url = 'https://gitee.com/coldmeaning/python-week06/raw/master/dict_search_AZURE/%E5%90%88%E7%85%A7.jpg'\n",
    "data = {                                     \n",
    "    'url': '{}'.format(img_url),\n",
    "}\n",
    "#需要进行的检测内容\n",
    "payload = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'flase',                                     \n",
    "    'returnFaceAttributes': '{}'.format('age,gender,glasses'), \n",
    "}\n",
    "#请求内容\n",
    "r = requests.post(BASE_URL,data=json.dumps(data),params = payload,headers=HEADERS) \n",
    "#返回的状态码\n",
    "r.status_code \n",
    "print(r)\n",
    "#用json输出结果                 \n",
    "result=r.json()                               \n",
    "result                                        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
